package org.java.search.util;

import org.java.item.entity.Sku;

import java.util.Date;
import java.util.Map;

/**
 * @author WHQ
 * @version 1.0
 * @date 2022-3-9 0009 下午 4:17
 */
public class MapToSku {
    public static Sku mapToSku(Map<String, Object> sourceAsMap){
        Sku sku=new Sku();
        Object lastUpdateTime = sourceAsMap.get("lastUpdateTime");
        //最后修改时间
        Date lastTime = new Date(Long.parseLong(lastUpdateTime.toString()));
        sku.setLastUpdateTime(lastTime);
        Object createTime = sourceAsMap.get("createTime");
        Date cTime = new Date(Long.parseLong(createTime.toString()));
        sku.setCreateTime(cTime);
        //到这里结束
        Object id = sourceAsMap.get("id");
        sku.setId(Long.parseLong(id.toString()));
        Object enable = sourceAsMap.get("enable");
        sku.setEnable(Boolean.parseBoolean(enable.toString()));
        Object images = sourceAsMap.get("images");
        sku.setImages(images.toString());
        Object indexes = sourceAsMap.get("indexes");
        sku.setIndexes(indexes.toString());
        Object inventory = sourceAsMap.get("inventory");
        sku.setInventory(Integer.parseInt(inventory.toString()));
        Object ownSpec = sourceAsMap.get("ownSpec");
        sku.setOwnSpec(ownSpec.toString());
        Object price = sourceAsMap.get("price");
        sku.setPrice(Long.parseLong(price.toString()));
        Object spuId = sourceAsMap.get("spuId");
        sku.setSpuId(Long.parseLong(spuId.toString()));
        Object name = sourceAsMap.get("title");
        sku.setTitle(name.toString());
        return sku;
    }
 }
